#include "../Header/Precompiled.h"
#include "../Header/LineSegment2D.h"

namespace Engine
{
	bool BuildLineSegment2D(LineSegment2D &LS, Vector2D Point0, Vector2D Point1)
	{
		// return failure if Point0 and Point1 are the same point
		if((Point0.x == Point1.x) && (Point0.y == Point1.y)) return false;

		//// set points of line segment ////
		LS.mP0 = Point0;
		LS.mP1 = Point1;

		//// calculate normal ////
		Vector2D edge = LS.mP1- LS.mP0;

		// rotate edge by -90 degrees
		float temp = edge.x;
		edge.x = edge.y;
		edge.y = -temp;

		// normalize and set line's normal
		LS.mN = Vector2DNormalize(edge);

		//// calculate normal * p0 ////
		LS.mNdotP0 = Vector2DDotProduct(LS.mN,LS.mP0);

		return true;
	}
}
